package pro.softzhang.algo.lc600;

/**
 * TODO 加练
 */
public class LC680_ValidPalindromeII {
    public static void main(String[] args) {
        String str = "abcaa";
        System.out.println(new Solution().validPalindrome(str));
    }

    static class Solution {
        public boolean validPalindrome(String s) {
            int hp = 0, tp = s.length() - 1;
            while (hp < tp) {
                if(s.charAt(hp) == s.charAt(tp)) {
                    hp++;
                    tp--;
                } else {
                    return isPalindrome(s.substring(hp + 1, tp + 1)) || isPalindrome(s.substring(hp, tp));
                }
            }
            return true;
        }

        public boolean isPalindrome(String s) {
            int hp = 0, tp = s.length() - 1;
            while (hp < tp) {
                if(s.charAt(hp) != s.charAt(tp)) {
                    return false;
                }
                hp++;
                tp--;
            }
            return true;
        }
    }
}
